package demo02_lock;

import sun.security.krb5.internal.Ticket;

/**
 * @author kunkun
 * @className TicketProblem_pro
 * @Description 买票问题
 * @date 2025/3/5 16:11
 */
public class TicketProblem_pro {

    public static void main(String[] args) {
        final Ticket ticket = new Ticket();
        new Thread(()->{while (ticket.ticketsNum>0) ticket.sail();},"A").start();
        new Thread(()->{while (ticket.ticketsNum>0) ticket.sail();},"B").start();
        new Thread(()->{while (ticket.ticketsNum>0) ticket.sail();},"C").start();
    }


    static class Ticket {

        private int ticketsNum = 20;

        public void sail() {
            System.out.println(Thread.currentThread().getName()+"购买第" + ticketsNum + "张票，剩余" + (ticketsNum--) + "张票");
        }

    }

}



